package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.ServiceDao;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class Controller {
    @Autowired
    ServiceDao serviceDao;
    @RequestMapping("showZx")
    public Object showZx(String date){
        List<Map> maps = serviceDao.showZx(date);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray catArray = new JSONArray();
        JSONArray serArray = new JSONArray();
        for (Map map : maps) {
            catArray.add(map.get("h"));
        }
        dataObject.put("categories",catArray);
        JSONObject serObject = new JSONObject();
        serObject.put("name","数量");
        JSONArray dataArray = new JSONArray();
        for (Map map : maps) {
            dataArray.add(map.get("cou"));
        }
        serObject.put("data",dataArray);
        serArray.add(serObject);
        dataObject.put("series",serArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }


    @RequestMapping("showBg")
    public Object showBg(String date){
        List<Map> maps = serviceDao.showBg(date);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        JSONObject object1 = new JSONObject();
        JSONObject object2 = new JSONObject();
        JSONObject object3 = new JSONObject();
        JSONObject object4 = new JSONObject();
        object1.put("name","来源");
        object1.put("id","subsys");
        jsonArray.add(object1);
        object2.put("name","订单总额");
        object2.put("id","module");
        jsonArray.add(object2);
        object3.put("name","下单人数");
        object3.put("id","business");
        jsonArray.add(object3);
        object4.put("name","订单数");
        object4.put("id","name");
        jsonArray.add(object4);
        dataObject.put("columns",jsonArray);
        JSONArray rowArray = new JSONArray();
        for (Map map : maps) {
            JSONObject rowObject = new JSONObject();
            rowObject.put("subsys",map.get("name"));
            rowObject.put("module",map.get("sum"));
            rowObject.put("business",map.get("num"));
            rowObject.put("name",map.get("cou"));
            rowArray.add(rowObject);
        }
        dataObject.put("rows",rowArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }


    @RequestMapping("showFp")
    public Object showFp(String date){
        List<Map> maps = serviceDao.showFp(date);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",maps.get(0).get("c"));
        return jsonObject;
    }


    @RequestMapping("showBg1")
    public Object showBg1(String date){
        List<Map> maps = serviceDao.showBg1(date);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        JSONObject object1 = new JSONObject();
        JSONObject object2 = new JSONObject();
        object1.put("name","课程");
        object1.put("id","subsys");
        jsonArray.add(object1);
        object2.put("name","下单金额");
        object2.put("id","module");
        jsonArray.add(object2);
        dataObject.put("columns",jsonArray);
        JSONArray rowArray = new JSONArray();
        for (Map map : maps) {
            JSONObject rowObject = new JSONObject();
            rowObject.put("subsys",map.get("course_name"));
            rowObject.put("module",map.get("sum"));
            rowArray.add(rowObject);
        }
        dataObject.put("rows",rowArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }
}
